<template>
  <div>
    <header>
      <nav>
        <span @click="fh">取消</span>
        <span>编辑名字</span>

        <button class="save" id="save" @click="bao">保存</button>
        
      </nav>
    </header>
    <div class="remind">7天内可修改一次名字</div>
    <div class="input_frame">
      <input
        type="text"
        id="name"
        placeholder="添加一个名字"
        maxlength="24"
        minlength="4"
        v-model="name"
      />
      <p>{{ name_length }}/24</p>
    </div>
    <div class="regulation">请设置 2-24个字符,不包括@/等无效字符哦</div>
  </div>
</template>

<script>
import { change_name } from "@/api/personal";

export default {
  data() {
    return {
      name_length: 2,
      name: "",
      d:''
    };
  },
  methods: {
    fh() {
      this.$router.go(-1);
      //返回上一页
    },

    bao() {
      let data = JSON.parse(localStorage.getItem("userid"));
      this.d =  data + "";
      change_name({
        uid: this.d,
        name: this.name,
      })
        .then((res) => {
          console.log(this.name);
          console.log(res);
        })
        .catch((rest) => {
          console.log(123);
        });
        this.$router.go(-1)
    },
  },
};
</script >

<style scoped>
header {
  width: 100%;
  height: 40px;
}
nav {
  height: 40px;
  display: flex;
  align-items: flex-end;
}
nav span:nth-child(1) {
  margin-left: 20px;
  font-size: 16px;
  color: rgb(190, 189, 189);
}
nav span:nth-child(2) {
  margin-left: 110px;
  font-size: 18px;
  color: rgb(0, 0, 0);
}
.remind {
  margin-top: 20px;
  margin-left: 30px;
  width: 160px;
  height: 20px;
  font-size: 14px;
}
.input_frame {
  margin-top: 10px;
  border-radius: 8px;
  margin-left: 20px;
  width: 350px;
  height: 40px;
  background-color: rgb(255, 255, 255);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
input {
  width: 180px;
  height: 30px;
  border: 0;
  outline: none;
  margin-left: 20px;
  background-color: rgb(255, 255, 255);
}
p {
  margin-right: 10px;
  color: rgb(156, 156, 156);
}
.regulation {
  width: 300px;
  color: rgb(190, 189, 189);
  font-size: 13px;
  margin-left: 30px;
  margin-top: 10px;
  /* display: none; */
}
.save {
  margin-left: 100px;
  font-size: 16px;
  color: rgb(255, 160, 160);
  background: transparent;
  border: 0;
}
</style>